<!DOCTYPE html>
<html lang="en">
  <head>
    <meta charset="UTF-8" />
    <meta name="viewport" content="width=device-width, initial-scale=1.0" />
    <meta http-equiv="X-UA-Compatible" content="ie=edge" />
    <title>Document</title>
    <style>
      /* 图片要移动不应该占位置，使用绝对定位 */
      img {
        position: absolute;
      }
    </style>
  </head>

  <body>
    <img src="../../images/angel.gif" alt="" />
    <script>
      var pic = document.querySelector("img");
      //鼠标移动事件 mousemove
      document.addEventListener("mousemove", function (e) {
        //每次鼠标移动，获取最新鼠标坐标
        var x = e.pageX;
        var y = e.pageY;
        //将获得的鼠标坐标给图片
        pic.style.left = x - 15 + "px";
        pic.style.top = y - 45 + "px";
      });
    </script>
  </body>
</html>
